Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

embed: only override default advertised client URL if the client listen URL is 0.0.0.0 #7027

Merged
merged 1 commit into from
Dec 17, 2016

Conversation

gyuho
Copy link
Contributor

@gyuho gyuho commented Dec 16, 2016

Fix #7009.

return "", err
}
if ip == "0.0.0.0" {
cfg.APUrls[0] = url.URL{Scheme: cfg.APUrls[0].Scheme, Host: fmt.Sprintf("%s:%s", h, port)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is misleading now; usually Is functions are idempotent. Here, cfg.IsDefaultHost() won't necessarily return the same value on subsequent calls. Probably should just have a separate function do to the advertise IP override.

return defaultHostname, defaultHostStatus
func (cfg *Config) IsDefaultHost() (string, error) {
h, herr := netutil.GetDefaultHost()
if len(cfg.APUrls) == 1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 0.0.0.0 check should be on the listen url. If 0.0.0.0, then the advertise urls need to be checked if they match the default url before overriding.

@gyuho gyuho changed the title embed: overwrite advertise URLs only when IP is 0.0.0.0 embed: overwrite advertise URLs when listen-url is 0.0.0.0 Dec 16, 2016
@gyuho gyuho force-pushed the default-host branch 2 times, most recently from 746c018 to 9cf5b31 Compare December 16, 2016 21:47
}
return "", defaultHostStatus
return false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this changes the meaning of the function though? This function was meant to say whether it's using the default hosts / user didn't specify, but now it's returning true if it's overriding the hosts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. How about NeedDefaultHost(), which means it returns true if it needs to detect machine's default host?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that will work-- IsDefaultHost means that it's using defaults (which may be overridden with the default route IP), not that it's using the default route IP. That will change the meaning of the InitialClusterFromName path, which needs to know whether the user set a host explicitly.

cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name)
needDefaultHost := cfg.IsDefaultHost()
if (needDefaultHost || cfg.Name != embed.DefaultName) && cfg.InitialCluster == defaultInitialCluster {
defaultHost, dhErr := netutil.GetDefaultHost()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this overriding stuff should be a function in embed.Config so it can be reused elsewhere

@gyuho gyuho changed the title embed: overwrite advertise URLs when listen-url is 0.0.0.0 embed: rewrite advertise url when listen-url is not 0.0.0.0 Dec 16, 2016
@gyuho gyuho changed the title embed: rewrite advertise url when listen-url is not 0.0.0.0 embed: only override default advertised client URL if the client listen URL is 0.0.0.0 Dec 16, 2016
@gyuho gyuho force-pushed the default-host branch 2 times, most recently from c1cc6ad to 65ca569 Compare December 16, 2016 23:33
@@ -89,6 +89,11 @@ func startEtcdOrProxyV2() {
defaultHostOverride := defaultHost == "" || defaultHostErr == nil
if (defaultHostOverride || cfg.Name != embed.DefaultName) && cfg.InitialCluster == defaultInitialCluster {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this path needs a lot of special support from Config and seems self-contained, can everything starting from IsDefaultHost() to the end of this if be func (cfg *Config) UpdateDefaultClusterFromName() instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heyitsanthony Just moved them all to embed.UpdateDefaultClusterFromName. PTAL. Thanks.

@gyuho gyuho force-pushed the default-host branch 2 times, most recently from 6cac0ca to 3dbd23b Compare December 17, 2016 01:07
@@ -356,6 +356,32 @@ func (cfg Config) IsDefaultHost() (string, error) {
return "", defaultHostStatus
}

// UpdateDefaultClusterFromName updates cluster advertise URLs with default host.
// TODO: check whether fields are set instead of whether fields have default value
func UpdateDefaultClusterFromName(cfg *Config, defaultInitialCluster string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func (cfg *Config) UpdateDefaultClusterFromName(defaultCluster string)?

}
}

func isDefaultRoute(host string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can probably inline this instead of a separate function?

return ip == "0.0.0.0"
}

func (cfg *Config) updateACURLHost(host string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@heyitsanthony
Copy link
Contributor

lgtm after fixing minor nits

@gyuho gyuho merged commit d62ce55 into etcd-io:master Dec 17, 2016
@gyuho gyuho deleted the default-host branch December 17, 2016 02:53
gyuho added a commit to gyuho/etcd that referenced this pull request Mar 1, 2017
Fix etcd-io#7348.

etcd-io#7027 broke this.
It overwriting the advertise-client-urls' host with 'localhost'.

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants